<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title><?= $page_title ?></title>
  <?php include(APPLICATION_BASE_TPL_PATH . "/inc/include.phtml"); ?>
  <!--include-wechat-start-->
  <?php include(APPLICATION_BASE_TPL_PATH . "/inc/include_wechat.phtml"); ?>
  <!--include-wechat-end-->
</head>
<body>
<div id="wrapper">
  <?php echo $menuview; ?>
  <div id="page-wrapper" style="min-height: 0;">
    <div class="row">
      <div class="panel panel-primary">
        <div class="panel-heading">
          <h3 class="panel-title"><?= $page_header ?></h3>
        </div>
        <div class="panel-body">
          <form class="form-horizontal" name="filter" method="get">
            <div class="form-group">
              <label for="list-oa" class="col-sm-1 control-label">微信号</label>
              <div class="col-sm-2">
                <select class="form-control" id="list-oa" name="oa">
                  <?php foreach ($oa_list as $acc): ?>
                    <?php if ($acc['handling']): ?>
                      <option value="<?= $acc['account'] ?>" selected><?= "{$acc['name']}"; ?></option>
                    <?php else: ?>
                      <option value="<?= $acc['account'] ?>"><?= "{$acc['name']}"; ?></option>
                    <?php endif; ?>
                  <?php endforeach; ?>
                </select>
              </div>

              <label class="col-sm-1 control-label" for="list-from">From</label>
              <div class="col-sm-3">
                <input type="text" class="form-control" name="from" id="list-from" value="<?=$from?>" placeholder="消息发送者的OpenID或微信号">
              </div>

              <label class="col-sm-1 control-label" for="list-stime-start">时间从</label>
              <div class="col-sm-3">
                <input type="datetime-local" class="form-control" name="stime-start" id="list-stime-start" value="<?=$stime_start?>" placeholder="消息发送时间YYYY-MM-DD HH:II">
              </div>

            </div>

            <div class="form-group">

              <label class="col-sm-1 control-label" for="list-type">类型</label>
              <div class="col-sm-2">
                <select class="form-control" id="list-type" name="type">
                  <option value="" selected>不限</option>
                  <?php foreach ($type_list as $item): ?>
                    <?php if ($item['selected']): ?>
                      <option value="<?= $item['id'] ?>" selected><?= "{$item['id']}-{$item['val']}"; ?></option>
                    <?php else: ?>
                      <option value="<?= $item['id'] ?>"><?= "{$item['id']}-{$item['val']}"; ?></option>
                    <?php endif; ?>
                  <?php endforeach; ?>
                </select>
              </div>


              <label class="col-sm-1 control-label" for="list-to">To</label>
              <div class="col-sm-3">
                <input type="text" class="form-control" name="to" id="list-to" value="<?=$to?>" placeholder="消息接收者的OpenID或微信号">
              </div>

              <label class="col-sm-1 control-label" for="list-stime-end">到</label>
              <div class="col-sm-3">
                <input type="datetime-local" class="form-control" name="stime-end" id="list-stime-end" value="<?=$stime_end?>" placeholder="消息发送时间YYYY-MM-DD HH:II">
              </div>

            </div>

            <button class="btn btn-primary btn-right btn-sm" type="submit" name="submit" value="submit">查询</button>

          </form>
        </div>
      </div>
    </div>
    <div class="row">

      <div class="panel panel-condensed panel-default panel-hover">
        <div class="panel-heading">
          <h5 class="panel-title"><span class="glyphicon glyphicon-list"></span> 往来记录</h5>
        </div>

        <?php if (empty($list)): ?>
          <div class="panel-body">此账号目前没有与用户进行任何消息交互.</div>
        <?php else: ?>

          <table class="table table-bordered table-responsive table-condensed table-hover">
            <thead>
            <tr>
              <th>ID</th>
              <th>FromUserName</th>
              <th>ToUserName</th>
              <th>类型</th>
              <th>内容</th>
              <th>发送时间</th>
              <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <?php foreach ($list as $item): ?>
              <tr>
                <td data-id="<?= $item['id'] ?>"><?= $item['id'] ?></td>
                <td style="text-align: left;"><?= $item['from'] ?></td>
                <td style="text-align: left;"><?= $item['to'] ?></td>
                <td style="text-align: right;"><?= $item['type_name'] ?></td>
                <td><?= $item['content'] ?></td>
                <td><?= $item['stime_YmdHis'] ?></td>

                <td style="text-align: center;">
                  <a role="button" data-action="update" data-original='<?= $item['msg_json'] ?>'
                     class="btn btn-xxs btn-default msg-original"><span class="glyphicon glyphicon-zoom-in"></span>
                    原始消息</a>
                </td>
              </tr>
            <?php endforeach; ?>
            </tbody>
          </table>

        <?php endif; ?>
      </div>
    </div>

    <div class="modal fade" tabindex="-1" id="modal-msg-original" role="dialog">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                  aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">原始消息</h4>
          </div>
          <div class="modal-body" style="padding:0;">
            <div class="modal-loading clearfix" style="display: none;">
              <div class="spinner float-left"></div>
              <div class="modal-loading-message float-left">正在保存,请稍候……</div>
            </div>
            <div class="modal-message" style="display: none;"></div>
            <div class="modal-inner-content" style="margin:0;">
              <pre style="border:0;margin-bottom: 0;"></pre>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
          </div>
        </div>
      </div>
    </div>


    <div class="row" style="display: none;">
      <pre><?php #var_export($type_list); ?></pre>
      <pre><?php #var_export($list); ?></pre>
      <pre><?php #var_export($oa_list); ?></pre>

    </div>
    <!-- /#page-wrapper -->

  </div>
  <!-- /#wrapper -->

</body>
<script type="text/javascript">

  $(function () {
    $('.msg-original').modalExt({
      modal: 'modal-msg-original',
      callback: {
        show: (function(){
          var $pre = undefined;
          return function(modal){
            if(!$pre) {
              $pre = modal.find$('pre');
            }
            $pre.html(JSON.stringify(modal.getData('original'), '', 2));
          }
        }())
      }
    });



  });
</script>
</html>
